﻿/*文件注释
 * ===============================================================================
 * 说明：
 * 作者：曾永佑
 * 版本：V1.0
 * 创建日期：2013-12-08
 * 完成日期： 
 * 修改纪录：  
 * ===============================================================================
 */  
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SRF.Security.Permission;
using SRF.Security.Principal;

namespace SRF.Components.Security
{
    public class MyDataRuleProvider : SRF.Security.DataRule.DataRuleProvider
    {
        readonly Data.DBHelperBase dbhelper = Data.DBHelperFactory.GetDBHelper();

        public override IDictionary<string, string> GetDataRules(IUser user)
        {
            var dataRules = new Dictionary<string, string>();
            foreach (var item in dbhelper.GetQuery(Constants.GetDataRulesByUserSQL)
                .SetParameter("UserId", user.Id).Dictionarys())
            {
                var key = item["Code"].ToString().ToLower();
                if (!key.StartsWith(SRF.Security.DataRule.DataRuleProvider.CodePrefix))
                {
                    key = CodePrefix + key;
                }
                dataRules.Add(key, item["Condition"].ToString());
            }


            return dataRules;
        }
    }
}